import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import axios from 'axios'
export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  const API_URL = 'http://geek.itheima.net/v1_0/channels'
  const channels = ref([])
  // async action
  async function fetchCount() {
    const response = await axios.get(API_URL)
    channels.value = response.data.data.channels
  }

  function increment() {
    count.value++
  }

  return { count, doubleCount, increment, channels, fetchCount }
})
